package ${package};

import cn.angis.common.annotation.SLog;
import cn.angis.common.model.PageModel;
import cn.angis.common.model.PageResult;
import cn.angis.common.model.R;
import cn.angis.common.annotation.SLog;
import cn.angis.db.controller.BaseController;
import cn.angis.${module}.dto.input.${className}Input;
import cn.angis.${module}.dto.output.${className}Output;
import cn.angis.${module}.dtomapper.${className}Struct;
import cn.angis.${module}.model.${className};
import cn.angis.${module}.service.${className}Service;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Get;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Post;
import org.noear.solon.validation.annotation.NotBlank;
import org.noear.solon.validation.annotation.NotEmpty;
import org.noear.solon.validation.annotation.Validated;

import java.util.List;

/**
* ${comment}前端控制器
* @author angis.cn
* @Date ${date(),"yyyy-MM-dd"}
*/
@SLog("${comment}")
@Mapping("/${module}/${lowerFirst(className)}/")
@Controller
public class ${className}Controller extends BaseController<${className}Service, ${className}> {

    /**
    * 分页查询
    * @param ${lowerFirst(className)}Input
    * @param pageModel
    * @return R<PageResult<${className}Output>>
    * @Date ${date(),"yyyy-MM-dd"}
    */
    @SLog
    @Get
    @Mapping("page")
    public R<PageResult<${className}Output>> page(${className}Input ${lowerFirst(className)}Input, PageModel pageModel) {
        ${className} ${lowerFirst(className)} = ${className}Struct.INSTANCE.to${className}(${lowerFirst(className)}Input);
        PageResult<${className}> pageResult = pageListByEntity(${lowerFirst(className)}, pageModel);
        List<${className}Output> ${lowerFirst(className)}OutputList = ${className}Struct.INSTANCE.toOutputList(pageResult.getRecords());
        return success(toPageDTO(pageResult, ${lowerFirst(className)}OutputList));
    }

    /**
    * 保存
    * @param ${lowerFirst(className)}Input
    * @return R<Boolean>
    * @Date ${date(),"yyyy-MM-dd"}
    */
    @SLog
    @Post
    @Mapping("save")
    public R<Boolean> save(@Validated ${className}Input ${lowerFirst(className)}Input) {
    ${className} ${lowerFirst(className)} = ${className}Struct.INSTANCE.to${className}(${lowerFirst(className)}Input);
        return super.save(${lowerFirst(className)});
    }

    /**
    * 修改
    * @param ${lowerFirst(className)}Input
    * @return R<Boolean>
    * @Date ${date(),"yyyy-MM-dd"}
    */
    @SLog
    @Post
    @Mapping("update")
    public R<Boolean> update(@Validated ${className}Input ${lowerFirst(className)}Input) {
        ${className} ${lowerFirst(className)} = ${className}Struct.INSTANCE.to${className}(${lowerFirst(className)}Input);
        return super.update(${lowerFirst(className)});
    }

    /**
    * 删除
    * @param id
    * @return R<Boolean>
    * @Date ${date(),"yyyy-MM-dd"}
    */
    @SLog
    @Post
    @Mapping("delete")
    public R<Boolean> delete(@NotBlank String id) {
        return super.delete(id);
    }

    /**
    * 批量删除
    * @param ids
    * @return R<Boolean>
    * @Date ${date(),"yyyy-MM-dd"}
    */
    @SLog
    @Post
    @Mapping("deleteBatch")
    public R<Boolean> deleteBatch(@NotEmpty List<String> ids) {
        return super.deleteBatch(${className}.class, ids);
    }
}
